package com.smartlink.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.jpush.api.JPushClient;
import cn.jpush.api.push.PushResult;
import cn.jpush.api.push.model.Platform;
import cn.jpush.api.push.model.PushPayload;
import cn.jpush.api.push.model.audience.Audience;
import cn.jpush.api.push.model.notification.Notification;

public class JpushUtil {
	protected static final Logger LOG = LoggerFactory.getLogger(JpushUtil.class);
	private static final String appKey = "0f7fc58ff5b61471cedc69c7";
	private static final String masterSecret = "f4207a0fe5c7b63902916213";
	public static final String TITLE = "Smart Link";

	/**
	 * 发送极光推送
	 * @param alert
	 */
	public static void sendJpush(String alert) {
		JPushClient jpushClient = new JPushClient(masterSecret, appKey);
		PushPayload payload = buildPushObject_android_alertWithTitle(alert);
		try {
			PushResult result = jpushClient.sendPush(payload);
			LOG.info(result.msg_id + "");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	private static PushPayload buildPushObject_android_alertWithTitle(String alert) {
		return PushPayload.newBuilder().setPlatform(Platform.android()).setAudience(Audience.all())
				.setNotification(Notification.android(alert, TITLE, null)).build();
	}
}
